﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ARS.Control.Custom.DataPaging.Widget
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:SearchInputText runat=server></{0}:SearchInputText>")]
    public class SearchInputText : Literal
    {
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string Text
        {
            get
            {
                String s = (String)ViewState["Text"];
                return ((s == null) ? String.Empty : s);
            }

            set
            {
                ViewState["Text"] = value;
            }
        }

        protected string GetInputHtml(string type)
        {
            return string.Format("<input id=\"{0}\" name=\"{0}\" type=\"{2}\"  class=\"dp_search\" value=\"{1}\" />",
                this.ID, Text, type);
        }

        public override void RenderControl(HtmlTextWriter writer)
        {
            writer.Write(this.GetInputHtml("tex"));
        }

        //protected override void RenderContents(HtmlTextWriter output)
        //{
        //    output.Write(string.Format("<input id=\"{0}\" name=\"{0}\" type=\"tex\"  class=\"dp_search\" />",this.ID));
        //    //output.Write(Text);
        //}
        /// <summary>
        /// 模糊查找
        /// </summary>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public string GetLikeWhere(string fieldName)
        {
            return string.Format("{0} like '%{{{{Text-{1}}}}}%'", fieldName, this.ID);
        }
        /// <summary>
        /// 相等
        /// </summary>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public string GetEqualWhere(string fieldName)
        {
            return string.Format("{0}='{{{{Text-{1}}}}}'", fieldName, this.ID);
            //ARS.Control.Request.Action;
        }
    }
}
